<?php
class M_Hotel extends Apps_Db_Table_Abstract {
    protected $_name = 'hotel';

    //get hotel best selling
    public function listHotelBestSelling() {
        $q = $this->_db
                  ->select()
                  ->from('hotel', null)
                  ->join('article', 'article.reference_id = hotel.id', null)
                  ->where('article.reference_type =? ', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
                  ->where('hotel.best_selling =? ', 1)
                  ->where('hotel.status =? ', 1)
                  ->order('hotel.sorting_number ASC')
                  ->columns(array('id'          => 'hotel.id',
                                  'thumbnail'   => 'article.thumbnail'));

        if($this->getLang() == 'en') {
            $q->columns(array('name'           => 'hotel.en_name',
                              'address'        => 'hotel.en_address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        } else {
            $q->columns(array('name'           => 'hotel.name',
                              'address'        => 'hotel.address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        }
        return $q;
    }
    //get hotel promotion
    public function listHotelPromotion() {
        $q = $this->_db
                  ->select()
                  ->from('hotel', null)
                  ->join('article', 'article.reference_id = hotel.id', null)
                  ->where('article.reference_type =? ', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
                  ->where('hotel.special_offer =? ', 1)
                  ->where('hotel.status =? ', 1)
                  ->order('hotel.sorting_number ASC')
                  ->columns(array('id'          => 'hotel.id',
                                  'thumbnail'   => 'article.thumbnail'));

        if($this->getLang() == 'en') {
            $q->columns(array('name'           => 'hotel.en_name',
                              'address'        => 'hotel.en_address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        } else {
            $q->columns(array('name'           => 'hotel.name',
                              'address'        => 'hotel.address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        }
        return $q;
    }

    //list hotel by region
    public function listHotelByRegion($regionId, $type) {
        $q = $this->_db
                  ->select()
                  ->from('hotel', null)
                  ->join('article', 'article.reference_id = hotel.id', null)
                  ->join('region', 'region.id = hotel.region_id', null)
                  ->join('hotel_type', 'hotel_type.id = hotel.hotel_type_id', null)
                  ->where('article.reference_type =? ', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
                  ->where('hotel.status =? ', 1)
                  ->where('region.id =? ', $regionId)
                  ->where('hotel_type.id =? ', $type)
                  ->order('hotel.rating DESC')
                  ->order('hotel.sorting_number ASC')
                  ->columns(array('id'          => 'hotel.id',
                                  'thumbnail'   => 'article.thumbnail'));

        if($this->getLang() == 'en') {
            $q->columns(array('name'           => 'hotel.en_name',
                              'address'        => 'hotel.en_address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        } else {
            $q->columns(array('name'           => 'hotel.name',
                              'address'        => 'hotel.address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer'));
        }
        return $q;
    }

    //get hotel by id
    public function getHotelById($id) {
        $q = $this->_db
                  ->select()
                  ->from('hotel', null)
                  ->join('article', 'article.reference_id = hotel.id', null)
                  ->join('region', 'region.id = hotel.region_id', null)
                  ->join('hotel_type', 'hotel_type.id = hotel.hotel_type_id', null)
                  ->where('article.reference_type =? ', M_DbTable_Article::REFERENCE_TYPE_HOTEL)
                  ->where('hotel.status =? ', 1)
                  ->where('hotel.id =? ', $id)
                  ->columns(array('id'          => 'hotel.id',
                                  'avatar'      => 'hotel.avatar',
                                  'phone'       => 'hotel.phone',
                                  'fax'         => 'hotel.fax',
                                  'meta_keyword'        => 'hotel.meta_keyword',
                                  'meta_description'    => 'hotel.meta_description',
                  				  'header_title'		=> 'hotel.header_title',
                                  'thumbnail'   => 'article.thumbnail'));

        if($this->getLang() == 'en') {
            $q->columns(array('name'           => 'hotel.en_name',
                              'address'        => 'hotel.en_address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'note_price'     => 'hotel.en_note_price',
                              'title'          => 'article.en_title',
                              'overview'       => 'article.en_overview',
                              'detail'         => 'article.en_detail'
                    ));
        } else {
            $q->columns(array('name'           => 'hotel.name',
                              'address'        => 'hotel.address',
                              'rating'         => 'hotel.rating',
                              'best_selling'   => 'hotel.best_selling',
                              'special_offer'  => 'hotel.special_offer',
                              'note_price'     => 'hotel.note_price',
                              'title'          => 'article.title',
                              'overview'       => 'article.overview',
                              'detail'         => 'article.detail'));
        }
        return $q;
    }
}